home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Comm / tcp / JabberwockySRC.lha / Jabberwocky / src / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-29  |  8.0 KB  |  288 lines

  1. /*  Copyright (C) 2002 Tom Parker (tom@carrott.org),
  2.                        Matthias Münch (matthias@amigaworld.de)
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  
  18.     In addition, as a special exception, Tom Parker and Matthias Münch give
  19.     permission to link the code of this program with a TCP stack of your 
  20.     choice, any official MUI libraries or classes and any custom MUI classes
  21.     that should be necessary for the operation of this program.  This 
  22.     exception also gives you permission to distribute linked combinations 
  23.     including this software with any of the before-mentioned libraries and 
  24.     classes.  You must obey the GNU General Public License in all respects for
  25.     all of the code used other than that provided by the before-mentioned 
  26.     libraries and classes.  As part of this exception you are obliged to 
  27.     follow the license terms of the before-mentioned libraries, this license
  28.     does not compel you to follow those terms, but if you do not then you may
  29.     not link with those libraries.  If you modify this file, you may extend
  30.     this exception to your version of the file, but you are not obligated to
  31.     do so.  If you do not wish to do so, delete this exception statement from
  32.     your version.
  33. */
  34. /*
  35. ** message read window
  36. */
  37.  
  38. #include "common.h"
  39.  
  40. #include <MUI/NListview_mcc.h>
  41. #include <MUI/NFloattext_mcc.h>
  42. #include <MUI/Mailtext_mcc.h>
  43.  
  44. #include <assert.h>
  45.  
  46. static ULONG read_new(struct IClass *cl, Object *obj, struct opSet *msg);
  47. static void read_show(struct readdata *data, jmessage *m);
  48. static void read_stat(struct readdata *data);
  49.  
  50.  
  51. MUI_DISPATCH(read_dispatch)
  52. {
  53.     switch(msg->MethodID)
  54.     {
  55.     case OM_NEW:
  56.         return read_new(cl, obj, (APTR)msg);
  57.  
  58.     case READ_CLOSE:
  59.     {
  60.         struct readdata *data = INST_DATA(cl,obj);
  61.         data->user->readwin = NULL;
  62.         DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
  63.         return 0;
  64.     }
  65.  
  66.     case READ_WRITE:
  67.     {
  68.         struct readdata *data = INST_DATA(cl,obj);
  69.         jmessage *m = data->user->readmsg;
  70.         if(!m) return(0);
  71.         write_to(iks_id_print(data->user->id), iks_find_cdata(m->pak->x, "thread"), NULL);
  72.         return 0;
  73.     }
  74.  
  75.     case READ_REPLY:
  76.     {
  77.         struct readdata *data = INST_DATA(cl,obj);
  78.         jmessage *m = data->user->readmsg;
  79.         if(!m) return(0);
  80.         write_to(iks_id_print(data->user->id), iks_find_cdata(m->pak->x, "thread"), iks_find_cdata(m->pak->x, "body"));
  81.         return 0;
  82.     }
  83.  
  84.     case READ_NEXT:
  85.     {
  86.         struct readdata *data = INST_DATA(cl,obj);
  87.         jmessage *m = NULL;
  88.         if(!data->user->readmsg)
  89.         {
  90.             if(data->user->msgs) data->user->readmsg = list_first(&data->user->msgs);
  91.         }
  92.         if(data->user->readmsg) m = list_next(data->user->readmsg);
  93.         if(m) read_show(data, m);
  94.         return 0;
  95.     }
  96.  
  97.     case READ_PREV:
  98.     {
  99.         struct readdata *data = INST_DATA(cl,obj);
  100.         jmessage *m = NULL;
  101.         if(data->user->readmsg) m = list_prev(data->user->readmsg);
  102.         if(m) read_show(data, m);
  103.         return 0;
  104.     }
  105.  
  106.     case READ_UPDATE:
  107.         read_stat(INST_DATA(cl,obj));
  108.         return 0;
  109.  
  110.     }
  111.     return DoSuperMethodA(cl,obj,msg);
  112. }
  113.  
  114.  
  115. static ULONG read_new(struct IClass *cl, Object *obj, struct opSet *msg)
  116. {
  117.     struct readdata *data;
  118.     Object *prevbut, *stat, *nextbut;
  119.     Object *errorlab, *errortxt;
  120.     Object *fromtxt, *thread, *text;
  121.     Object *writebut, *repbut, *closebut;
  122.  
  123.     obj = (Object *)DoSuperNew(cl,obj,
  124.         MUIA_Window_Title, MSG_READ_TITLE,
  125.         MUIA_HelpNode, "window-readmsg",
  126.         WindowContents, VGroup,
  127.             Child, HGroup,
  128.                 Child, prevbut = mui_button(MSG_READ_PREV),
  129.                 Child, (ULONG) stat = TextObject,
  130.                     TextFrame,
  131.                     MUIA_Background, MUII_TextBack,
  132.                 End,
  133.                 Child, nextbut = mui_button(MSG_READ_NEXT),
  134.             End,
  135.             Child, ColGroup(2),
  136.                 Child, Label1(MSG_READ_FROM),
  137.                 Child, (ULONG) fromtxt = TextObject,
  138.                     TextFrame,
  139.                     MUIA_Background, MUII_TextBack,
  140.                 End,
  141.                 Child, Label1(MSG_READ_THREAD),
  142.                 Child, (ULONG) thread = TextObject,
  143.                     TextFrame,
  144.                     MUIA_Background, MUII_TextBack,
  145.                 End,
  146.                 Child, (ULONG) errorlab = Label1(MSG_READ_ERROR),
  147.                 Child, (ULONG) errortxt = TextObject,
  148.                     TextFrame,
  149.                     MUIA_Background, MUII_TextBack,
  150.                 End,
  151.             End,
  152.             Child, NListviewObject,
  153.                     MUIA_NListview_NList, (ULONG) text = MailtextObject,
  154.                         MUIA_Mailtext_Text,              text,
  155.                         MUIA_Mailtext_ForbidContextMenu, FALSE,
  156.                         MUIA_Frame,                      MUIV_Frame_InputList,
  157.                         MUIA_NList_Input,                FALSE,
  158.                         MUIA_NList_MultiSelect,          FALSE,
  159.                     End,
  160.                     MUIA_CycleChain, TRUE,
  161.             End,
  162.             Child, HGroup,
  163.                 Child, writebut = mui_button(MSG_READ_WRITE),
  164.                 Child, repbut = mui_button(MSG_READ_REPLY),
  165.                 Child, closebut = mui_button(MSG_READ_CLOSE),
  166.             End,
  167.         End,
  168.         TAG_MORE, msg->ops_AttrList);
  169.  
  170.     if(!obj) {
  171.         con_debug("error creating new read window!");
  172.         return(0);
  173.     }
  174.     
  175. /*
  176.     set(errorlab, MUIA_ShowMe, FALSE);
  177.     set(errortxt, MUIA_ShowMe, FALSE);
  178. */
  179.     data = INST_DATA(cl,obj);
  180.     data->user = (juser)GetTagData(READ_FROM, NULL, msg->ops_AttrList);
  181.     data->fromtxt = fromtxt;
  182.     data->thread = thread;
  183.     data->text = text;
  184.     data->prevbut = prevbut;
  185.     data->stat = stat;
  186.     data->nextbut = nextbut;
  187.     data->errorlab = errorlab;
  188.     data->errortxt = errortxt;
  189.  
  190.     if(data->user->readmsg)
  191.     {
  192.         if(data->user->readmsg->flags & MSG_READ && list_next(data->user->readmsg))
  193.             data->user->readmsg = list_next(data->user->readmsg);
  194.         read_show(data, data->user->readmsg);
  195.     }
  196.     else
  197.     {
  198.         if(data->user->msgs)
  199.             read_show(data, list_first(&data->user->msgs));
  200.     }
  201.  
  202.     DoMethod(prevbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, READ_PREV);
  203.     DoMethod(repbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, READ_REPLY);
  204.     DoMethod(writebut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, READ_WRITE);
  205.     DoMethod(nextbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, READ_NEXT);
  206.  
  207.     DoMethod(closebut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, READ_CLOSE);
  208.     DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 1, READ_CLOSE);
  209.     
  210.     return((ULONG)obj);
  211. }
  212.  
  213.  
  214. static void read_show(struct readdata *data, jmessage *m)
  215. {
  216.     juser u = data->user;
  217.  
  218.     if(!m) return;
  219.  
  220.     if (!(m->flags & MSG_READ)) {
  221.         if (u->event) {
  222.             u->event--;
  223.             roster_refresh(u);
  224.         }
  225.         m->flags |= MSG_READ;
  226.     }
  227.  
  228.     u->readmsg = m;
  229.  
  230.     if(u->name)
  231.         set(data->fromtxt, MUIA_Text_Contents, (ULONG) my_printf("%s (%s)", u->name, convert_locale(iks_id_print(m->pak->from))));
  232.     else
  233.         set(data->fromtxt, MUIA_Text_Contents, (ULONG) convert_locale(iks_id_print(m->pak->from)));
  234.  
  235.     set(data->thread, MUIA_Text_Contents, (ULONG) convert_locale(iks_find_cdata(m->pak->x, "thread")));
  236.     set(data->text, MUIA_Mailtext_Text, (ULONG) convert_locale(iks_find_cdata(m->pak->x, "body")));
  237.  
  238.     if(m->pak->subtype == IKS_TYPE_ERROR)
  239.     {
  240.         set(data->errortxt, MUIA_Text_Contents, (ULONG) convert_locale(iks_find_cdata(m->pak->x, "error")));
  241. /*        set(data->errorlab, MUIA_ShowMe, TRUE);
  242.         set(data->errortxt, MUIA_ShowMe, TRUE);
  243. */    }
  244.     else
  245.     {
  246.         set(data->errortxt, MUIA_Text_Contents, NULL);
  247. /*        set(data->errorlab, MUIA_ShowMe, FALSE);
  248.         set(data->errortxt, MUIA_ShowMe, FALSE);
  249. */    }
  250.  
  251.     read_stat(data);
  252.  
  253. }
  254.  
  255.  
  256. static void read_stat(struct readdata *data)
  257. {
  258.     u_long tmp;
  259.     jmessage *m = data->user->readmsg;
  260.  
  261.     if(!m) return;
  262.  
  263.     if(list_next(m)) tmp = FALSE; else tmp = TRUE;
  264.     set(data->nextbut, MUIA_Disabled, tmp);
  265.     if(list_prev(m)) tmp = FALSE; else tmp = TRUE;
  266.     set(data->prevbut, MUIA_Disabled, tmp);
  267. }
  268.  
  269.  
  270. void read_from(juser u)
  271. {
  272.     Object *win;
  273.     
  274.     assert(u);
  275.     
  276.     if(u->readwin) {
  277.         DoMethod(u->readwin, MUIM_Window_ToFront);
  278.         return;
  279.     }
  280.  
  281.     win = NewObject(gui.read_mcc->mcc_Class, NULL, READ_FROM, (ULONG) u, TAG_DONE);
  282.     if(win) {
  283.         DoMethod(gui.app, OM_ADDMEMBER, win);
  284.         set(win, MUIA_Window_Open, TRUE);
  285.         u->readwin = win;
  286.     }
  287. }
  288.